<template>
	<view>
		<view>
			<u-navbar title=" " :background="{ background: '#ffffff'}" :border-bottom="false">
				<view class="slot-wrap">
					<view @click="openEdit()">
						<u-icon name="more-dot-fill" color="#000000" size="32"></u-icon>
					</view>
				</view>
			</u-navbar>
		</view>
		<view class="friendInfo">
			<view class="img">
				<u-image 	:src="friendInfo.avatar"
							@tap="previewImg(friendInfo.avatar)"
							mode="aspectFill" width="120" height="120" border-radius="12">
					<u-loading slot="loading"></u-loading>
					<view slot="error"
							class="u-flex u-row-center u-col-center  u-p-t-10"
							style="width: 90rpx;height: 90rpx;background-color: #f1f1f1;border-radius: 12rpx;">
						<view>
							<image src="/static/image/default/default-user/default-user.png" 
									style="width: 64rpx;height: 64rpx;"></image>
						</view>
					</view>
				</u-image>
			</view>

			<view class="friendInfo-desc u-p-t-10">
				<view class="friendInfo-desc-name">
					<text class="u-m-r-10" style="font-size: 42rpx;">{{friendInfo.realName}}</text>
					<u-icon  top="6rpx"v-if="friendInfo.sex==0" name="/static/image/chat/addFriend/man.png" size="30"></u-icon>
					<u-icon top="10rpx"  v-else   name="/static/image/chat/addFriend/woman.png" size="32"></u-icon>
				</view>
				<view class="friendInfo-desc-gray u-m-t-10">地区：{{parseAddress(friendInfo.address)}}</view>
			</view>
		</view>
	
		<u-cell-group>
			<u-cell-item title="设置备注和标签"  :border-bottom="false" 
			:title-style="titleStyle"  hover-class="my-cell-hover-class"
			 @click="setFiendTag"></u-cell-item>
			<u-gap height="20" bg-color="#eee" margin-top="1" margin-bottom="1"></u-gap>
		     <template >
				<u-cell-item  title="" :title-style="titleStyle"  :arrow="false" hover-class="my-cell-hover-class">
					<view slot="title" class="u-flex u-row-left u-col-center">
						<view style="width: 150rpx;text-align: left;" class="">
							<text>个性签名</text>
						</view>
						<view 	 v-if="friendInfo.signature"
								style="margin-left: 50rpx;color: #75777b;text-align: left;font-size: 32rpx;">
							<view>{{friendInfo.signature}}</view>
						</view>
					</view>
				</u-cell-item>
			</template>
			<u-cell-item title="" :title-style="titleStyle"  :border-bottom="false" :arrow="false" hover-class="my-cell-hover-class">
				<view slot="title" class="u-flex u-row-left u-col-center">
					<view style="width: 150rpx;text-align: left;" class="">
						<text>来源</text>
					</view>
					<view style="margin-left: 50rpx;color: #75777b;font-size: 32rpx;">
						<text>来自手机号搜索</text>
					</view>
				</view>
			</u-cell-item>
		</u-cell-group>
		<view>
			<u-gap height="20" bg-color="#eee" margin-top="0" margin-bottom="1"></u-gap>
			<u-cell-group>
				<template v-if="fromPage==2">
					<u-cell-item :arrow="false" :border-bottom="false" @click="toAddFriend()">
						<view class="u-flex u-row-center u-col-center"
								style="font-size: 32rpx;color: #36648b;text-align: center;">
							<view>
								<text style="margin-left: 10rpx;">添加到通讯录</text>
							</view>
						</view>
					</u-cell-item>
				</template>
				<template v-else>
					<u-cell-item :arrow="false" :border-bottom="false" @click="aggreApply(1)">
						<view class="u-flex u-row-center u-col-center"
								style="font-size: 32rpx;color: #9ca0a6;text-align: center;">
							<view>
								<text style="margin-left: 10rpx;">等待对方验证</text>
							</view>
						</view>
					</u-cell-item>
				</template>
			</u-cell-group>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleStyle: {
					marginLeft: '10rpx',
					color: '#000000',
					fontSize: "34rpx",
				},
				friendId:"",
				isFriend:false,
				applyUserInfo:{},
				friendInfo: {},
				isItMe: false,
				callList:[
					{text: '视频通话'},
					{text: '语音通话'}
				],
				callShow:false,
				fromPage:0,
			}
		},
		onLoad(option) {
			let  newFriendInfo= option.newFriendInfo;
			if(newFriendInfo!=null&&newFriendInfo.length>0){
				let objStr= decodeURIComponent(newFriendInfo);
				let  newFriendInfoObj= JSON.parse(objStr);
				console.log("添加好友信息",newFriendInfoObj);
				this.friendInfo=newFriendInfoObj;
			};
			let fromPage=option.fromPage;
			if(fromPage!=null&&fromPage!=undefined){
				this.fromPage=fromPage;
			}
		},
		methods: {
			//地址信息格式化	
			parseAddress:function(address){
				let addressStr="中国";
				if(address!=null&&address.length>0){
					let addressObj= JSON.parse(address);
					let provice= addressObj.province.label;
					let city=addressObj.city.label;
					addressStr=provice+" "+city;
					/* let area=addressObj.area.label;
					addressStr=provice+" "+city+" "+area;
					let detail=addressObj.detail;
					if(detail!=null&&detail!=undefined){
						this.addressDetail=detail.label;
					} */
				}
				return addressStr;
			},
			//设置标签
			setFiendTag() {
				this.globalUtil.utilAlert("不能进,没完事~敬请期待");
				return;
			},
			//预览朋友的头像
			previewImg(urls) {
				if(urls!=null&&urls!=undefined){
					uni.previewImage({
						urls: [urls]
					})
				}
			},
			//更多信息
			linkToMoreInfoMation() {
				this.$u.route({
					url: "/pages/tabbar/contact/friends/friend-more-info",
					params: {
						signature: this.friendInfo.signature
					}
				})
			},
			aggreApply:function(status){
				/* let that=this;
				let item= this.friendInfo;
				let param={
					applyUserId:item.id,
					status:status
				}
				console.log("处理申请",item);
				that.$u.api.imUser.handleFriendApply(param).then(res => {
					if(res.code==200&&res.data!=null){
						uni.navigateBack();
					}
				}) */
			},
			
			toAddFriend:function(){
				this.$u.route({
					url: '/pages/tabbar/contact/friends/submit-add-new-friend',
					params: {newFriendInfo:encodeURIComponent(JSON.stringify(this.friendInfo)),fromPage:2}
				});
			},
			
			//设置角标
			setBadgeNum:function(){
				that.$u.api.imUser.unHandleFriendApply({}).then(res => {
					if(res.code==200&&res.data!=null){
						let badgeNumber=res.data;
						if(badgeNumber<1){
							uni.removeTabBarBadge({
								index:1
							});
							that.$u.route({
								 type:'reLaunch',
								 url:'/pages/tabbar/contact/contact-list'
							});
						}else{
							let number=badgeNumber.toString();
							uni.setTabBarBadge({
							  index: 1,
							  text: number
							})
						}
					}else{
						uni.removeTabBarBadge({
							index:1
						})
					}
				})
			},
		},

	}
</script>

<style scoped lang="scss">
	.slot-wrap {
		display: flex;
		align-items: center;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		flex: 1;
		width: 100%;
		/* 如果您想让slot内容与导航栏左右有空隙 */
		padding: 0 30rpx;
		flex-direction: row;
		justify-content: flex-end;
	}

	.perch {
		height: 10rpx;
	}

	.friendInfo {
		display: flex;
		justify-content: flex-start;
		align-items: flex-start;
		padding: 20rpx 30rpx 40rpx 40rpx;
		background-color: #FFFFFF;

		.img {
			display: block;
			width: 130rpx;
			height: 130rpx;
			border-radius: 10rpx;
		}

		&-desc {
			padding-left: 30rpx;

			&-name {
				font-weight: bold;
				font-size: 36rpx;
				transform: translateY(-10rpx);
				color: #000000;
			}

			&-gray {
				color: $u-tips-color;
				font-size: 30rpx;
			}
		}
	}
</style>
<style>
	page{
		background-color: #eeeeee;
	}
</style>